package com.dotflat.check.domain.C.PO;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.annotation.JSONField;
import lombok.Data;

import javax.xml.bind.JAXBException;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlRootElement;
import java.util.List;

@Data
@XmlRootElement(name = "GetAttendanceCardResult")  // 父节点名称
@XmlAccessorType(XmlAccessType.FIELD) //定义这个类中的何种类型需要映射到XML
public class GetAttendanceCardResultPO {

    @JSONField(name = "AccessControlUserId")
    Long AccessControlUserId =  0l;
    @JSONField(name = "CardNo")
    String CardNo = "";
    @JSONField(name = "CardType")
    Integer CardType = 0;
    @JSONField(name = "CreateTime")
    String CreateTime = "";
    @JSONField(name = "Id")
    Integer Id = 0;
    @JSONField(name = "KgId")
    Integer KgId = 0;
    @JSONField(name = "Reason")
    String Reason = "平台销卡";
    @JSONField(name = "RelateId")
    Integer RelateId = 0;
    @JSONField(name = "State")
    Integer State = 1;
    @JSONField(name = "UpdateTime")
    String UpdateTime = "";
    @JSONField(name = "UserId")
    Integer UserId = 0;

    /**
     * 将对象转为流程XML
     *
     * @return
     * @throws JAXBException
     */
    public static String convertToXML(List<GetAttendanceCardResultPO> list) {
        String data = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n" +
                "<soap:Envelope xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\">\n" +
                "    <soap:Body>\n" +
                "        <GetAttendanceCardResponse xmlns=\"http://tempuri.org/\">\n" +
                "            <GetAttendanceCardResult>${v}</GetAttendanceCardResult>\n" +
                "        </GetAttendanceCardResponse>\n" +
                "    </soap:Body>\n" +
                "</soap:Envelope>";
        String xmlStr = JSON.toJSONString(list);
        data = data.replace("${v}", xmlStr);
        return data;
    }

}
